package cn.iune.erp.accounting;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Aspect//指定这是一个其切面
public class AccountVoucherDetailDaoAspect {
	
	@Autowired
	private IAccountingService accountingService;
	
	//指定切入点（增加）
    @Pointcut("execution(* cn.iune.erp.accounting.IAccountVoucherDetailDao.insert(..)) && args(obj)")
    public void insertPointCut(AccountVoucherDetail obj){}
    
    //指定通知以及通知的范围
    @Transactional
    @After("insertPointCut(obj)")
    public void afterInsert(AccountVoucherDetail obj){
    	accountingService.afterInsert(obj);
    }
    
	//指定切入点（删除）
    @Pointcut("execution(* cn.iune.erp.accounting.IAccountVoucherDetailDao.delete(..)) && args(fID)")
    public void deletePointCut(String fID){}
    
    //指定通知以及通知的范围
    @Transactional
    @Before("deletePointCut(fID)")
    public void beforeDelete(String fID){
    	accountingService.beforeDelete(fID);
    }
	//指定切入点（修改）
    @Pointcut("execution(* cn.iune.erp.accounting.IAccountVoucherDetailDao.update(..)) && args(obj)")
    public void updatePointCut(AccountVoucherDetail obj){}
    
    //指定通知以及通知的范围
    @Transactional
    @Around("updatePointCut(obj)")
    public AccountVoucherDetail aroundUpdate(JoinPoint joinPoint, AccountVoucherDetail obj) throws Throwable{
		//删除之前
    	accountingService.beforeDelete(obj.getfID());
    	AccountVoucherDetail objNew = (AccountVoucherDetail) ((ProceedingJoinPoint) joinPoint).proceed();
		//插入之后
    	accountingService.afterInsert(obj);
		return objNew;
    }

}
